<?php
namespace app\common\exception;

use Exception;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;

class Http extends Handle
{
    public function render(Exception $e)
    {
        // 参数验证错误
        if ($e instanceof ValidateException) {
            return json(['msg'=>$e->getMessage(),'code'=>ERRNO['PARAMERR']]);
        }

        if($e instanceof \Firebase\JWT\ExpiredException){
            return json(['msg'=>$e->getMessage(),'code'=>$e->getCode()]);
        }

        // 请求异常
        if ($e instanceof HttpException && request()->isAjax()) {
            return json(['msg'=>$e->getMessage(),'code'=>ERRNO['REQUESTERR']]);
        }

        return json(['msg'=>$e->getMessage(),'code'=>ERRNO['SERVERERR']]);
        // 其他错误交给系统处理
//        return parent::render($e);
    }

}